<?php
include("../../Connections/connect_client.php");
$rate=intval($_POST["rate"]);
$id=intval($_POST["id"]);
$query="SELECT n.MarkerNum, n.Rating FROM news n WHERE n.NewsID=$id";
$res=mysql_query($query);
$row1=mysql_fetch_assoc($res);
$avg=floatval($row1["Rating"]);
$nums=intval($row1["MarkerNum"]);
$avg=round((($avg*$nums)+$rate)/($nums+1),2);
$query="UPDATE news SET MarkerNum = MarkerNum+1 ,Rating = $avg WHERE NewsID=$id";
if(mysql_query($query))
{
	$res=array('total'=>$nums+1,'ok'=>true);
}
else
{
	$res=array('total'=>$nums,'ok'=>false);
}
echo json_encode($res);

?>